#include <stdio.h>
#include <stdlib.h>
#include <tslib.h>

int main(int argc, char *argv[])
{
    struct tsdev *ts=NULL;
    struct ts_sample samp;
    int pressure = 0;           // 上次按压值
    int x,y;                    // 上次x y值

    /* 打开并配置触摸屏 */
    ts = ts_setup(NULL, 0);
    if (ts == NULL) {
        fprintf(stderr, "ts_setup error");
        exit(EXIT_FAILURE);
    }

    /* 读数据 */
    while (1) {
        if (ts_read(ts, &samp, 1) < 0) {
            fprintf(stderr, "ts_read error");
            ts_close(ts);
            exit(EXIT_FAILURE);
        }

        if (samp.pressure) {
            if (pressure > 0) {
                if (samp.x != x || samp.y != y) {
                    printf("移动(%d, %d)\n", samp.x, samp.y);
                }
            } else {
                printf("按下(%d, %d)\n", samp.x, samp.y);
            }
        } else {
            printf("松开\n");
        }

        pressure = samp.pressure;
        x = samp.x;
        y = samp.y;
    }

    ts_close(ts);
    exit(EXIT_SUCCESS);
}